package com.seean.clock.utils;

/**
 * mybatisplus 的逆向工程
 * @authur wsx
 * @date 2019/8/14 11:38
 */
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyBatisGenerator {
    // 先生成，再移动xml到resources路径下
    public static void main(String[] args) {
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        //项目 地址E:\mywork\idea\ideaproject\springboot-dev
        gc.setOutputDir("E:\\mywork\\idea\\ideaproject\\springboot-dev\\src\\main\\java");
        gc.setFileOverride(true);//文件覆盖
        gc.setActiveRecord(true);// 不需要ActiveRecord特性的请改为false
        gc.setEnableCache(false);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(true);// XML columList
        gc.setAuthor("wsx");
        gc.setServiceName("%sService");//去掉前缀I

        // 数据源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("root");
        dsc.setPassword("123456");
        dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test?useSSL=false&serverTimezone=UTC");

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        //strategy.setInclude("sys_dept");
        //strategy.setInclude("sys_dict");
        //strategy.setInclude("sys_log");
        //strategy.setInclude("sys_menu");
        //strategy.setInclude("sys_oauth_client_details");
        //strategy.setInclude("sys_role");
        //strategy.setInclude("sys_role_menu");
        //strategy.setInclude("sys_social_details");
        //strategy.setInclude("sys_user");
        //strategy.setInclude("sys_user_role");
        //strategy.setInclude("sys_dept_relation");

        strategy.setNaming(NamingStrategy.underline_to_camel);//下划线转驼峰命名

        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.seean.clock");
        pc.setMapper("mapper.user");
        pc.setEntity("model.user");
        pc.setXml("mapper.user.xml");
        pc.setService("service.user");
        pc.setController("controller.user");


        //整合配置
        AutoGenerator mpg = new AutoGenerator();
        mpg.setGlobalConfig(gc);
        mpg.setDataSource(dsc);
        mpg.setStrategy(strategy);
        mpg.setPackageInfo(pc);

        // 执行生成
        mpg.execute();
        System.out.println("生成完毕");
    }

}
